#include "StdAfx.h"
#include "ConfigManage.h"


ConfigManage::ConfigManage(void)
{
	ZeroMemory(&m_struFixConfig,sizeof(struFixConfig));
}


ConfigManage::~ConfigManage(void)
{

}

int ConfigManage::LoadConfigFile()
{	
	m_struFixConfig.nSocketAcceptPort = GetPrivateProfileInt(_T("DEFAULT"),_T("SocketAcceptPort"),9001,(LPCTSTR)g_lpCfgPath);
	GetPrivateProfileString(_T("DEFAULT"),_T("SenderCompID"),_T("ACCEPT"),m_struFixConfig.szSenderCompID,sizeof(m_struFixConfig.szSenderCompID)-1,(LPCTSTR)g_lpCfgPath);
	GetPrivateProfileString(_T("DEFAULT"),_T("StartTime"),_T("00:00:00"),m_struFixConfig.szStartTime,sizeof(m_struFixConfig.szStartTime)-1,(LPCTSTR)g_lpCfgPath);
	GetPrivateProfileString(_T("DEFAULT"),_T("EndTime"),_T("00:00:00"),m_struFixConfig.szEndTime,sizeof(m_struFixConfig.szEndTime)-1,(LPCTSTR)g_lpCfgPath);
	m_struFixConfig.IsAutoStart = GetPrivateProfileInt(_T("CONTROL"),_T("SvrAutoStart"),0,(LPCTSTR)g_lpCfgPath);
	m_struFixConfig.nLogRetainDays = GetPrivateProfileInt(_T("CONTROL"),_T("LogRetainDays"),30,(LPCTSTR)g_lpCfgPath);
	m_struFixConfig.nLastTradeDay = GetPrivateProfileInt(_T("CONTROL"),_T("LastTradeDay"),0,(LPCTSTR)g_lpCfgPath);	

	//GetPrivateProfileString(_T("DEFAULT"),_T("ConnectionType"),_T("acceptor"),m_struFixConfig.szConnectionType,sizeof(m_struFixConfig.szConnectionType)-1,(LPCTSTR)g_lpCfgPath);
	//GetPrivateProfileString(_T("DEFAULT"),_T("SocketReuseAddress"),_T("Y"),m_struFixConfig.szSocketReuseAddress,sizeof(m_struFixConfig.szSocketReuseAddress)-1,(LPCTSTR)g_lpCfgPath);
	//GetPrivateProfileString(_T("DEFAULT"),_T("FileStorePath"),_T("fixstore"),m_struFixConfig.szFileStorePath,sizeof(m_struFixConfig.szFileStorePath)-1,(LPCTSTR)g_lpCfgPath);
	//GetPrivateProfileString(_T("DEFAULT"),_T("DataDictionary"),_T(".\FIX42.xml"),m_struFixConfig.szDataDictionary,sizeof(m_struFixConfig.szDataDictionary)-1,(LPCTSTR)g_lpCfgPath);

	return S_OK;
}

int ConfigManage::UpdateConfigFile()
{
	CString str = _T("");	

	str.Format("%d",m_struFixConfig.nSocketAcceptPort);
	WritePrivateProfileString(_T("DEFAULT"),_T("SocketAcceptPort"),str,(LPCTSTR)g_lpCfgPath);
	WritePrivateProfileString(_T("DEFAULT"),_T("SenderCompID"),m_struFixConfig.szSenderCompID,(LPCTSTR)g_lpCfgPath);	
	WritePrivateProfileString(_T("DEFAULT"),_T("StartTime"),m_struFixConfig.szStartTime,(LPCTSTR)g_lpCfgPath);
	WritePrivateProfileString(_T("DEFAULT"),_T("EndTime"),m_struFixConfig.szEndTime,(LPCTSTR)g_lpCfgPath);
	str.Format("%d",m_struFixConfig.IsAutoStart);
	WritePrivateProfileString(_T("CONTROL"),_T("SvrAutoStart"),str,(LPCTSTR)g_lpCfgPath);

	str.Format("%d",m_struFixConfig.nLogRetainDays);
	WritePrivateProfileString(_T("CONTROL"),_T("LogRetainDays"),str,(LPCTSTR)g_lpCfgPath);

	str.Format("%d",m_struFixConfig.nLastTradeDay);
	WritePrivateProfileString(_T("CONTROL"),_T("LastTradeDay"),str,(LPCTSTR)g_lpCfgPath);

	WritePrivateProfileString(_T("DEFAULT"),_T("ConnectionType"),_T("acceptor"),(LPCTSTR)g_lpCfgPath);
	WritePrivateProfileString(_T("DEFAULT"),_T("SocketReuseAddress"),"Y",(LPCTSTR)g_lpCfgPath);
	WritePrivateProfileString(_T("DEFAULT"),_T("FileStorePath"),_T("Fixstore"),(LPCTSTR)g_lpCfgPath);
	WritePrivateProfileString(_T("DEFAULT"),_T("DataDictionary"),_T(".\\FIX42.xml"),(LPCTSTR)g_lpCfgPath);

	return S_OK;
}
